<?php  include  $this->admin_tpl('header'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo JS_PATH;?>EasyUI/themes/haidaoblue/easyui.css">
<link rel="stylesheet" type="text/css" href="<?php echo JS_PATH;?>EasyUI/themes/icon.css">
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>EasyUI/hd_default_config.js"></script>
<script type="text/javascript" src="/template/default/statics/js/area.js"></script>
<script>var ajaxurl = "/index.php?m=admin&c=union&a=getArea";</script>
<script>var ajaxagencyurl = "/index.php?m=admin&c=agency&a=getAgency";</script>
	<div class="content">
	<div class="site">
	<?php echo C('site_name')?> <a href="#">代理商管理</a> > 代理商列表
	</div>
    <div id="cc" class="easyui-calendar"></div>
	<span class="line_white"></span>
	<div class="goods mt10">
		<div class="search_ind">
			<input type="hidden" name="m" value="<?php echo GROUP_NAME ?>">
			<input type="hidden" name="c" value="<?php echo MODULE_NAME ?>">
			<input type="hidden" name="a" value="<?php echo ACTION_NAME ?>">
            <span style="margin-right: 10px;">选择代理商</span>
				<select name='province_data' id='province'  data-options="editable:false"  onChange="loadArea(this.value, 'city');"  style="height: 26px; width:100px; float:left">
                <option value="-1" selected>--请选择省份--</option>
                    <?php
                        foreach($region as $v){
						?>
                    <option value="<?php echo $v["area_id"]?>" <?php if($info["province"]==$v["area_id"]){?> selected="selected"<?php }?>><?php echo $v["area_name"]?></option>
                    <?php
						}
						?>
                </select>
                <select name='city_data' id='city' data-options="editable:false"  onChange="loadArea(this.value, 'district')"  style="height: 26px; width:100px; float:left">
                <option value="-1">--请选择城市--</option>
                     <?php
                        foreach($city as $v){
						?>
                    <option value="<?php echo $v["area_id"]?>" <?php if($info["city"]==$v["area_id"]){?> selected="selected"<?php }?>><?php echo $v["area_name"]?></option>
                    <?php
						}
					?>
                </select>
                <select name='district_data' id='district' data-options="editable:false"  onChange="loadAgency(this.value, 'agency')"   style="height: 26px; width:100px; float:left">
                     <option value="-1">--请选择地区--</option>
                    <?php
						
                        foreach($district as $v){
						?>
                    <option value="<?php echo $v["area_id"]?>" <?php if($info["district"]==$v["area_id"]){?> selected="selected"<?php }?>><?php echo $v["area_name"]?></option>
                    <?php
							  }
						?>
                </select>
                 <select name='agency_data' id='agency' data-options="editable:false" style="height: 26px; width:100px; float:left">
                     <option value="-1">--请选择代理商--</option>
                    <?php
                        foreach($agency as $v){
						?>
                    <option value="<?php echo $v["id"]?>" <?php if($info["district"]==$v["id"]){?> selected="selected"<?php }?>><?php echo $v["realname"]?></option>
                    <?php
						}
					?>
                </select>
                 <span style="margin-right: 10px;">营业额统计开始时间 </span>
                <input class="easyui-datebox" name="start" id="start" data-options="sharedCalendar:'#cc'">
                <span style="margin-right: 10px;">至</span>
                <input class="easyui-datebox" name="end" id="end" data-options="sharedCalendar:'#cc'" validType="md['#start']">
                
			<a id="search" href="#" class="easyui-linkbutton" style="height: 26px;padding-right: 10px;">查询</a>
		</div>
		<div class="login mt10" style="border: none;border-right: 1px solid #e6e6e6;">
			<table id="order_list_grid" style="width:100%;"></table> 
		</div>
		<div class="clear"></div>
		<?php include $this->admin_tpl('copyright') ?>
	</div>
</div>
	<script type="text/javascript">
		$(function() {
		//批量操作
			$(".batch").hover(function() {
				$(this).find("p").show();
				}, function() {
				$(this).find("p").hide();
			});
		})
		//改变状态架
		function corderstatus(ftype,val) {
			var arr = [];
			$("input[name='selid[]']:checked").each(function() {
				arr.push($(this).val());
			});
			if (arr.length == 0) {
				alert('请选择操作项目');
				return false;
			}
			$.post("<?php echo U('AdminOrder/ajax_status');?>", {"ftype":ftype ,"id": arr.toString(), "val": val}, function(data) {
				if (data.status == 1) {
				location.reload();
				}
			})
		}
		//切换
		$(function() {
			var tabTitle = ".mt10 dt p a";
			$(tabTitle).click(function(){
				$(this).siblings("a").removeClass("hover").end().addClass("hover");
			});
		});
	</script> 
	<!--表格js-->
	<script type="text/javascript">
	var dom = $('#order_list_grid');
	var pageSize = <?php echo PAGE_SIZE?>;
	var dataurl = '<?php echo U('countinfo')?>';
	var addurl = '<?php echo U('add')?>';
	var editurl = '<?php echo U('add',array('opt'=>'edit'))?>';
	var delurl = '<?php echo U('add',array('opt'=>'del'))?>';
	var keyword = '<?php echo $keyword?>';
	$(function(){
		dom.datagrid({
			url:dataurl, 
			striped:true,
			width:'100%',
			title:"统计概览",  
			checkOnSelect:false,
			fitColumns:true,
			toolbar:[
				{
					id:'exportrows',
					text:'导出',
					iconCls:'icon-export',
				},'-'
			],
			frozenColumns:[[
				{field:'id',checkbox:true}
			]],
			queryParams:{
				keyword:keyword,
			},
			scrollbarSize:0,
			pagination:true,
			pageSize:pageSize,
			pageList: [pageSize,pageSize*4,pageSize*8,pageSize*16,pageSize*32,pageSize*64],
			//可以设置每页记录条数的列表 
			columns:[[
				{field:'username',title:'会员名',fixed:true,align:'center',width:'10%'},
				{field:'agency_name',title:'代理商',fixed:true,align:'center',width:'7%'},
				{field:'compayname',title:'公司名称',fixed:true,align:'center',width:'8%'},
				{field:'compayid',title:'营业执照编号',fixed:true,align:'center',width:'5%'},
				{field:'address2',title:'公司地址',fixed:true,align:'center',width:'25%'},
				{field:'compaycounent',title:'联系人',fixed:true,align:'center',width:'5%'},
				{field:'mobile_phone',title:'手机号',fixed:true,width:'5%',align:'center'},
				{field:'true_name',title:'真实姓名',align:'center',width:'4%',align:'center'},
				{field:'user_money',title:'余额',width:'5%',align:'center',sortable:true},
				{field:'sell_money',title:'总营业额',width:'5%',align:'center',sortable:true},
				{field:'sell_num',title:'订单数量',width:'5%',align:'center',sortable:true},
				{field:'return_money',title:'商家返点<?php echo C('agency') ?>%',width:'6%',align:'center',sortable:true},
				{field:'reg_time',title:'注册时间',width:'8%',align:'center',sortable:true,
					formatter:function(value,row,index){
  						return $.fn.datebox.defaults.timeformat(value);
					}
				},
			]],onLoadSuccess:function(data){
				$(".panel-title").html(data.title);
			}
			
		});
		$('#addrow').bind('click', function(){
			window.location.href=addurl;
		})
		$('#exportrows').bind('click', function(){
			var queryParams = dom.datagrid('options').queryParams;
			//查询参数直接添加在queryParams中
			queryParams.start = $('#start').datebox('getValue');
			queryParams.end = $('#end').datebox('getValue');
			queryParams.agency = $("#agency").val();
			dom.datagrid('options').queryParams = queryParams;
			window.location.href="/index.php?m=admin&c=agency&a=countinfo&act=excel&agency="+queryParams.agency+"&start="+queryParams.start+"&end="+queryParams.end;
		});
		//回车查询
		$('#keyword').textbox('textbox').bind('keydown',function (e) {
			if (e.keyCode == 13) {
				$('#search').trigger('click');
			}
		});
		$('#delrows').bind('click', function(){
			var ids = [];
			var rows = dom.datagrid('getSelections');
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].id);
			}
			if (ids.length > 0){
				$.messager.confirm('确认','您确认想要删除记录吗？',function(r){
					if (r){
						$.getJSON(delurl,
						{"id[]":ids},
						function(data){
							if(1 == data.status){// 删除成功，则需要在树中删除节点
								dom.datagrid("reload");  //重新加载
							}else{
								$.messager.alert('警告',data.info);
							}
						})
					}else{
						dom.datagrid('clearSelections').datagrid('clearChecked');
					}
				});
			}else{
				$.messager.alert('警告','请选择要删除的记录');
				return false;
			}
		});
	});
	
	//增加查询参数，重新加载表格
	$('#search').bind('click',function (){
		var queryParams = dom.datagrid('options').queryParams;
		//查询参数直接添加在queryParams中
		queryParams.start = $('#start').datebox('getValue');
		queryParams.end = $('#end').datebox('getValue');
		queryParams.agency = $("#agency").val();
		dom.datagrid('options').queryParams = queryParams;
		dom.datagrid('reload');
	})
	
</script>